package com.bazaaroid.client.web.gwt.partnermodule.client.view.common;

import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class TitleCommandBar extends Composite {

	private Label titleLabel;
	private HorizontalPanel titlePanel = new HorizontalPanel();
	private Widget lastCommand;
	
	public TitleCommandBar(String title) {
		initWidget(titlePanel);
		titlePanel.setWidth("100%");
		setStyleName("productTitle");
		titleLabel = new Label(title);
		titleLabel.setStyleName("");
		titleLabel.setWordWrap(false);
		titlePanel.add(titleLabel);
		titlePanel.setCellVerticalAlignment(titleLabel, HasVerticalAlignment.ALIGN_MIDDLE);
	}
	
	public void addWidget(Widget widget) {
		if( lastCommand != null )
			titlePanel.setCellWidth(lastCommand, "");
		lastCommand = widget;
		titlePanel.add(lastCommand);
		titlePanel.setCellWidth(lastCommand, "100%");
		titlePanel.setCellVerticalAlignment(lastCommand, HasVerticalAlignment.ALIGN_MIDDLE);
	}

	public void addCommand(String name, ClickHandler handler) {
		Hyperlink hyperlink = new Hyperlink(name, "");
		hyperlink.addClickHandler(handler);
		hyperlink.setStyleName("productLink");
		addWidget(hyperlink);
	}
	
	public Label getTitleLabel() {
		return titleLabel;
	}
	
}
